﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CinemaSystem
{
    public partial class FormYH : Form
    {
        public FormYH()
        {
            InitializeComponent();
        }
        string sqlstr;
        DataTable dt = new DataTable();
        private void FormYH_Load(object sender, EventArgs e)
        {
            sqlstr = string.Format("select * from [User]");
            dt = DBHelper.GetDataTable(sqlstr);
            dataGridView1.DataSource = dt;
        }
        int k;
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            k = e.RowIndex;
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((MessageBox.Show("您是否确定要删除？", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                  == DialogResult.Yes))
            {

                int id = int.Parse(dt.Rows[k]["Userid"].ToString());
                string sqlstr = string.Format("delete [User] where Userid={0}", id);
                int i = DBHelper.ExecuteNonQuery(sqlstr);
                if (i > 0)
                {
                    MessageBox.Show("删除成功！");

                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sqlstr = string.Format("select * from [User]");
            dt = DBHelper.GetDataTable(sqlstr);
            dataGridView1.DataSource = dt;
        }
    }
}
